<template>
<div class="">
    <div class="pr10">
        <div class="analyItem">
            <p class="analyItemTit tx-center">状态</p>
            <div class="analyItemCon">
                <div class="col-md-12">
                    <p class="col-md-3">
                        <span class="cGreen pr8" title="当前阶段">{{leftInfo.AfterMarketState | stage}}</span>
                    </p>
                    <p class="col-md-3">
                        <span class="cGreen pr8" title="进入该阶段的日期">{{leftInfo.AfterMarketStateTime}}</span>
                    </p>
                    <p class="col-md-3">
                        <span class="cGreen pr8">未开启</span>
                    </p>
                    <span class="circlemark circlemark-lightGreen">正</span>
                </div>
            </div>
        </div>
    </div>
    <div class="thinScroll pr10" v-scrollHeight="84">
        <div v-if="leftInfo.AfterMarketState === 10">
            <router-link  v-for="(item,index) in personorderAuditList"  :key="index" tag="div" exact
            :to="{name:'personOrder',params:{workerTypeId : item.id}, query: {ind: index}}"
            class="analyItem anItemBor" active-class="anItemBor-active">
                <p class="analyItemTit tx-center">{{item.name}}</p>
                <div class="analyItemCon">
                    <div class="col-md-12">
                        <p class="col-md-4"><span class="cLightGray pr8">天数</span><span>{{item.hour ? item.hour.toFixed(2) : ''}}</span></p>
                        <p class="col-md-4"><span class="cLightGray pr8">金额</span><span>{{item.money ? item.money.toFixed(2) : ''}}元</span></p>
                        <p class="col-md-4"><span class="cLightGray pr8">工人</span><span>{{item.manNums ? item.manNums : ''}}</span></p>
                    </div>
                </div>
            </router-link>
        </div>
        <div v-if="leftInfo.AfterMarketState > 10">
             <router-link  v-for="(item,index) in personorderList"  :key="index" tag="div" exact
            :to="{name:'personOrder',params:{workerTypeId : item.workerTypeId}, query: {ind: index}}"
            class="analyItem anItemBor" active-class="anItemBor-active">
                <p class="analyItemTit tx-center">{{item.workerTypeName }}</p>
                <div class="analyItemCon">
                    <div class="col-md-12">
                        <p class="col-md-2"><span class="cLightGray pr8">预  / 实人 </span><span class="dis-block">{{item.workerNumber}} / {{item.workerActiveNumber}}</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">工时</span><span class="dis-block">{{item.workingDay !== '' || item.workingDay !== null  ? item.workingDay.toFixed(2) : ''}}天</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">计划</span><span class="dis-block">{{item.planMoney !== '' || item.planMoney !== null  ? item.planMoney.toFixed(2) : '' }}</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">实际</span><span class="dis-block">{{item.workerActiveNumber !== '' || item.workerActiveNumber !== null  ? item.workerActiveNumber.toFixed(2) : ''}}</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">剩余</span><span class="dis-block">{{(item.planMoney  -  item.projectMoney).toFixed(2) }}</span></p>
                    </div>
                </div>
            </router-link>
        </div>
    </div>
    <div class="pr10">
        <div v-if="leftInfo.AfterMarketState === 10">
            <div class="analyItem">
                <p class="analyItemTit tx-center">处理</p>
                <div class="analyItemCon">
                    <div class="col-md-12">
                        <p class="col-md-3"><span class="cLightGray pr8">工种</span><span>{{ personorderAuditList.length }}</span></p>
                        <p class="col-md-3"><span class="cLightGray pr8">天数</span><span>{{ workDay }}</span></p>
                        <p class="col-md-3"><span class="cLightGray pr8">金额</span><span>{{ workMoney }}元</span></p>
                        <p class="col-md-3"><span class="cLightGray pr8">工人</span><span>{{ worker }} </span></p>
                    </div>
                </div>
            </div>
        </div>
        <div v-if="leftInfo.AfterMarketState > 10">
            <div class="analyItem">
                <p class="analyItemTit tx-center">处理</p>
                <div class="analyItemCon">
                    <div class="col-md-12">
                        <p class="col-md-2"><span class="cLightGray pr8">预  / 实人 </span><span class="cGreen dis-block">{{ personScale }}</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">工时</span><span class="cGreen dis-block">{{ workingDay }}天</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">计划</span><span class="cGreen dis-block">{{ planMoney }}</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">实际</span><span class="cGreen dis-block">{{ projectMoney }}</span></p>
                        <p class="col-md-2"><span class="cLightGray pr8">剩余</span><span class="cGreen dis-block">{{ money }}</span></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { getTypeOfWork, getOrderWorkTypeWagesList } from '../Resources/Api/order'
export default {
    data () {
        return {
            personorderAuditList: [], // 审计人工
            personorderList: [] // 准备 在施人工
        }
    },
    created () {
        this.load()
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo']),
        workMoney () {
            let money = 0
            this.personorderAuditList.forEach(item => {
                money += item.money
            })
            return money.toFixed(2)
        },
        workDay () {
            let days = 0
            this.personorderAuditList.forEach(item => {
                days += item.hour
            })
            return days.toFixed(2)
        },
        worker () {
            let workerNumber = 0
            this.personorderAuditList.forEach(item => {
                workerNumber += item.manNums
            })
            return workerNumber
        },
        personScale () {
            let plan = 0
            let reality = 0
            this.personorderList.forEach(item => {
                let workerNumber = 0
                let workerActiveNumber = 0
                if (item.workerNumber === null || item.workerNumber === '') {
                    workerNumber = 0
                } else {
                    workerNumber = item.workerNumber
                }
                if (item.workerActiveNumber === null || item.workerActiveNumber === '') {
                    workerActiveNumber = 0
                } else {
                    workerActiveNumber = item.workerActiveNumber
                }
                plan += workerNumber
                reality += workerActiveNumber
            })
            return `${plan} / ${reality}`
        },
        workingDay () {
            let workingDay = 0
            this.personorderList.forEach(item => {
                workingDay += item.workingDay
            })
            return workingDay.toFixed(2)
        },
        planMoney () {
            let money = 0
            this.personorderList.forEach(item => {
                money += item.planMoney
            })
            return money.toFixed(2)
        },
        projectMoney () {
            let money = 0
            this.personorderList.forEach(item => {
                money += item.projectMoney
            })
            return money.toFixed(2)
        },
        money () {
            let plan = 0
            let reality = 0
            this.personorderList.forEach(item => {
                let money = 0
                let projectMoney = 0
                if (item.planMoney === null || item.planMoney === '') {
                    money = 0
                } else {
                    money = item.planMoney
                }
                if (item.projectMoney === null || item.projectMoney === '') {
                    projectMoney = 0
                } else {
                    projectMoney = item.projectMoney
                }
                plan += money
                reality += projectMoney
            })
            return (plan - reality).toFixed(2)
        }
    },
    methods: {
        // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        },
        load () {
            // 用_this 代替this
            let _this = this
            _this.loading = true
            // 接口请求
            if (this.leftInfo.AfterMarketState === 10) {
                let parm = {
                    rwdID: _this.leftInfo.orderno
                }
                // 审计人工
                getTypeOfWork(parm).then((result) => {
                    if (result.data.statusCode === 1) {
                        _this.personorderAuditList = result.data.body
                    }
                }).catch((err) => {
                    console.log(err)
                })
            } else {
                let parmer = {
                    orderNo: _this.leftInfo.orderno
                }
                // 准备 在施人工
                getOrderWorkTypeWagesList(parmer).then((result) => {
                    if (result.data.StatusCode === 1) {
                        _this.personorderList = result.data.Body
                    }
                }).catch((err) => {
                    console.log(err)
                })
            }
        }
    },
    watch: {
        leftInfo () {
            this.load()
        }
    },
    filters: {
        stage (parone) {
            let value = ''
            switch (parone) {
            case 0:
            case 10:
                value = '审计'
                break
            case 20:
                value = '准备'
                break
            case 30:
                value = '在施'
                break
            case 31:
                value = '施前'
                break
            case 32:
                value = '施中'
                break
            case 33:
                value = '施尾'
                break
            case 40:
                value = '竣工'
                break
            case 50:
                value = '完工'
                break
            case 60:
                value = '历史'
                break
            case 70:
                value = '坏账'
                break
            case 80:
                value = '退单'
                break
            }
            return value
        }
    }
}
</script>
